local qingya = fk.CreateSkill {
  name = "lingling__qingya",
  --tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__qingya"] = "倾轧",
  --[":lingling__qingya"] = "锁定技，当一名其他角色死亡时，若你体力上限小于6，你加1点体力上限，然后摸两张牌；当一名其他角色本轮首次进入濒死状态时，若你体力值大于1，你失去1点体力，然后摸两张牌。",
  [":lingling__qingya"] = "回合开始时，你可以随机对一名角色造成1点伤害。",

  ["lingling__yanguang_EasterEgg"] = "独孤误我！",
}

qingya:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(qingya.name) and target == player
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local ids = table.map(room.alive_players,Util.IdMapper)
    local tos = table.random(ids,1)
    for i = 1, 2, 1 do
      for _, p in ipairs(room:getAlivePlayers()) do
        room:delay(350)
        if table.contains(tos,p.id) and i == 2 then
          room:doIndicate(player.id, {p.id})
          room:setEmotion(p, "./image/anim/selected")
          break
        else
          room:setEmotion(p, "./image/anim/selectable")
          room:notifyMoveFocus(p, qingya.name)
        end
      end
    end
    for _, id in ipairs(tos) do
      local p = room:getPlayerById(id)
      if not p.dead then
          room:damage{
            from = player,
            to = p,
            damage = 1,
            skillName = qingya.name,
          }
      end
    end
  end,
})

--[[qingya:addEffect(fk.Death, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(qingya.name) and player.maxHp < 6
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 1)
    if not player.dead then
      player:drawCards(2, qingya.name)
    end

    if target.general == "lingling__yangjian" and player.general == "lingling__yangguang" and not player.dead then
      room:sendLog{
        type = "#lingling__yanguang_EasterEgg",
        from = player.id,
        toast = true,
      }
      local cards = {
        room:printCard("ling__jade_seal", Card.Club, 1).id,
      }
      room:moveCardIntoEquip(player, cards, nil, false, player)
    end
  end,
})

qingya:addEffect(fk.EnterDying, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(qingya.name) and target ~= player and player.hp > 1 then
      local dying_events =  player.room.logic:getEventsOfScope(GameEvent.Dying, 1, function (e)
        return e.data.who == target
      end, Player.HistoryRound)
      return #dying_events == 1 and dying_events[1].data == data
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, qingya.name)
    if not player.dead then
      player:drawCards(2, qingya.name)
    end
  end,
})]]--

return qingya
